#include "AnaDef.h"
#include "AnaAliDef.h"

int main(int argc, char *argv[])
{
  for(int ii=0; ii<argc; ii++)
    printf("%d %s\n", ii, argv[ii]);

  TFile::Open(argv[1]);

  AliCDBEntry *cdb = (AliCDBEntry *)gDirectory->Get("AliCDBEntry");
  if(!cdb){
    gDirectory->ls();
    printf("cdb null!\n");
    return 1;
  }

  TObjArray * objs = (TObjArray *) cdb->GetObject();
  TTreeSRedirector *fStream = new TTreeSRedirector("ocdbtree.root");

  for(Int_t iter=0; iter<objs->GetSize(); iter++){
    TObjArray *obji = (TObjArray*)objs->At(iter);
    if(!obji) 
      continue;

    const TString hname(obji->GetName());

    TVectorD *aa=0x0;
    aa=(TVectorD*) obji->At(0);
    
    for(Int_t ibin=0; ibin<aa->GetNrows(); ibin++){
      Double_t cont = (*aa)[ibin];

      (*fStream)<<"ocdb"<<
        "iobj="<<iter<<
        "ibin="<<ibin<<
        "cont="<<cont<<
        "\n";

      if(fabs(cont)>1e-12){
        printf("%soutcalibobj%s %d %15.6e\n", fabs(cont)>1e-12 ? "" : "NN", hname(11,10).Data(), ibin, cont);
      }
    }
  }

  delete fStream;
}
